import React from 'react';
import { Collapse, Form, Radio, Input } from 'antd';
import trans from '@/utils/translate';

interface Props {
  tabImage?: string;
  setStart?: any;
  start: string;
};

const { Panel } = Collapse;
const { Item } = Form;
const { Group } = Radio;

const AdvancedConfiguration: React.FC<Props> = (props) => {
  const optionsRestart = [
    { label: trans('deployOnline.edgeInference.add.restartAlways'), value: 'always' },
    { label: trans('deployOnline.edgeInference.add.restartOnFailure'), value: 'on-failure' },
    { label: trans('deployOnline.edgeInference.add.noRestart'), value: 'no' },
  ];

  const getTip = (key: string, f: boolean) => {
    const tips = new Map([
      [
        f ? trans('deployOnline.edgeInference.add.restartAlways') : 'always',
        trans('deployOnline.edgeInference.add.restartAlwaysTip')
      ],
      [
        f ? trans('deployOnline.edgeInference.add.restartOnFailure') : 'on-failure',
        trans('deployOnline.edgeInference.add.restartOnFailureTip')
      ],
      [
        f ? trans('deployOnline.edgeInference.add.noRestart') : 'no',
        trans('deployOnline.edgeInference.add.noRestartTip')
      ],
    ]);
    return tips.get(key) || tips.get('always');
  };

  return (
    <Collapse defaultActiveKey={['0']}>
      <Panel
        header={trans('deployOnline.edgeInference.add.runCmd')}
        key='1'
        // extra={trans('deployOnline.edgeInference.add.runCmdAttention')}
        extra={<span style={{color:'#ccc',fontSize:'12px'}}>
          {trans('deployOnline.edgeInference.add.runCmdAttention')}
          </span>}
      >
        <Item
          label={trans('deployOnline.edgeInference.add.runCmd')}
          name='containerRunCmd'
        >
          <Input
            disabled={props.tabImage==='public'}
            placeholder={trans('deployOnline.edgeInference.add.runCmdTip')}></Input>
        </Item>
        <Item
          label={trans('deployOnline.edgeInference.add.runParams')}
          name='containerRunParams'
        >
          <Input.TextArea
            disabled={props.tabImage==='public'}
            placeholder={trans('deployOnline.edgeInference.add.runParamsTip')}></Input.TextArea>
        </Item>
      </Panel>
      {/* <Panel header={trans('deployOnline.edgeInference.add.privilegeOptions')} key='2'>
        <Item label={trans('deployOnline.edgeInference.add.privilegeOptions')} name='containerPrivilegeMode'>
          <Switch></Switch>
          <p>{trans('deployOnline.edgeInference.add.privilegeOptionsTip')}</p>
        </Item>
      </Panel> */}
      {/* <Panel header={trans('deployOnline.edgeInference.add.restartStrategy')} key='3'> */}
      <Panel header={trans('deployOnline.edgeInference.add.restartStrategy')} key='2'>
        <Item
          label={trans('deployOnline.edgeInference.add.restartStrategy')}
          name='containerResart'
        >
          <Group
            // disabled={Boolean(props.tabImage) || !props.setStart}
            onChange={e => props.setStart(e.target.value)}
            defaultValue='always'
            options={optionsRestart}
            optionType="button"
            buttonStyle="solid"></Group>
          <p>{getTip(props.start, !props.setStart)}</p>
        </Item>
      </Panel>
    </Collapse>
    )
}

export default AdvancedConfiguration;
